package uk.ac.glasgow.oose2.gcf.view.lui;

import uk.ac.glasgow.oose2.gcf.model.CalculatorException;
import uk.ac.glasgow.oose2.gcf.model.ScientificCalculator;
/**
 * 
 * Line view for Scientific calculator - shows how to extend LuiBasic
 *  
 * @author J Sventek
 * @author tws
 * @version 1.0
 */

/*
 * Tasks for extending LuiBasic
 * 1. provide constructor, deferring to super()
 * 2. override displayError to print LuiScientific instead of LuiBasic
 * 3. override attemptCommand()
 */

public class LuiScientific extends LuiBasic {
	
	/** Gives access to the scientific calculator's full interface */
	private ScientificCalculator sciCalc;

	public LuiScientific(ScientificCalculator theCalc) {
		super(theCalc);
		this.sciCalc = theCalc;
	}
	
	/**
	 * Overrides displayError so that lines printed indicate that it comes from LuiScientific
	 */
	public void displayError(String err) {
		System.err.println("LuiScientific/" + err);
	}
	
	/**
	 * Override attemptCommand to process Scientific-specific commands
	 * Defer to super.attemptCommand() for unrecognized commands
	 */
	public void attemptCommand(String buf) throws CalculatorException {
		try {
			if (buf.equalsIgnoreCase("e"))
				sciCalc.e();
			else if (buf.equalsIgnoreCase("ln"))
				sciCalc.ln();
			else if (buf.equalsIgnoreCase("exp"))
				sciCalc.exp();
			else if (buf.equalsIgnoreCase("pow"))
				sciCalc.pow();
			else if (buf.equalsIgnoreCase("rad"))
				sciCalc.rad();
			else if (buf.equalsIgnoreCase("sin"))
				sciCalc.sin();
			else if (buf.equalsIgnoreCase("cos"))
				sciCalc.cos();
			else if (buf.equalsIgnoreCase("tan"))
				sciCalc.tan();
			else super.attemptCommand(buf);
		} catch (CalculatorException ex) {
			throw ex;
		}
	}
}